package org.sharing.action;

import org.sharing.service.SharingManagerService;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;

public class UserManageAction extends ActionSupport{

String id[];
	
	public String[] getId() {
		return id;
	}
	public void setId(String[] id) {
		this.id = id;
	}
	
	String target;
	
	public String getTarget() {
		return target;
	}
	public void setTarget(String target) {
		this.target = target;
	}

	SharingManagerService sharingManagerService;
	
	public void setSharingManagerService(SharingManagerService sharingManagerService) {
		this.sharingManagerService = sharingManagerService;
	}

	public String del() throws Exception {
		ActionContext ctx = ActionContext.getContext();
		String b[] = (String[]) ctx.getParameters().get("id");
		sharingManagerService.del(Integer.parseInt(b[0]));
		setTarget(ctx.getSession().get("url").toString().substring(4));
		return SUCCESS;
	}
	public String cancel() throws Exception {
		ActionContext ctx = ActionContext.getContext();
		String b[] = (String[]) ctx.getParameters().get("id");
		System.out.println(b[0]);
		sharingManagerService.change(Integer.parseInt(b[0]),1);
		setTarget(ctx.getSession().get("url").toString().substring(4));
		return SUCCESS;
	}
	public String finsh() throws Exception {
		ActionContext ctx = ActionContext.getContext();
		String b[] = (String[]) ctx.getParameters().get("id");
		System.out.println(b.length);
		sharingManagerService.change(Integer.parseInt(b[0]),4);
		setTarget(ctx.getSession().get("url").toString().substring(4));
		return SUCCESS;
	}
	public String delAll() throws Exception {
		String b[] = getId();
		for(int i = 0; i < b.length; i++)
			sharingManagerService.del(Integer.parseInt(b[i]));
		ActionContext ctx = ActionContext.getContext();
		setTarget(ctx.getSession().get("url").toString().substring(4));
		return SUCCESS;
	}
}
